import inspect
import sys,os,time
p=os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
p=os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(p))))
p=p+os.sep+'_base_tool'+os.sep+'python'
sys.path.append(p)
from base_class1_0 import base_class # type: ignore
import tornado.ioloop  
import tornado.web  
import json as JSON
class a_1_0_2_1_0(base_class):
    #第一次运行 接收到参数后 注册url路径以及绑定响应函数http_handle
    def run(self,http_obj,method,url,**kwargs):
        http初始化组件_id,http初始化组件_所在进程,http通信监听端口=http_obj
        print("开始注册快速访问url")
        if http初始化组件_所在进程==self._process_id:
            print("当前进程")
            self._all_obj[http初始化组件_id].fast_find_obj[method].add(
                path=url,
                handle=self.http_handle
            )
            # print("http初始化组件_id",type(http初始化组件_id),method)
            # print("j",self._all_obj['1'].fast_find_obj['get'].fast_dict,id(self._all_obj['1'].fast_find_obj['get'].fast_dict))
        else:
            pass
    #匹配到url后 输出路径以及数据
    def http_handle(self,data,path,**k):
        tornado_self=data
        out_params={
            "url":path,
            "head_params":tornado_self.head_params,
            "body_json":tornado_self.body_json,
            "body_params":tornado_self.body_params,
            "tornado_self":tornado_self#用于回复用户时调用 tornado_self.write("ok")
            }
        print("接收请求处理中:",path)
        #接收到mqtt数据后 将数据输出到接收数据的组件
        self.out(out_params)    

        